﻿using System;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;




namespace Common.Location
{
    [DefaultClassOptions]
    [ImageName ("BO_Country")]
    public class Country : BaseObject
    {
        public Country(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();

            _isActive = true;
            _isDefault = false;
        }

        private string _name;
        private string _tag;
        private string _iso2code;
        private string _iso3code;
        private bool _isActive;
        private bool _isDefault;


        [RuleRequiredField("Country_Name", DefaultContexts.Save)]
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                SetPropertyValue("Name", ref _name, value);
            }
        }

        public string Tag
        {
            get
            {
                return _tag;
            }
            set
            {
                SetPropertyValue("Tag", ref _tag, value);
            }
        }

        [Indexed(Unique = true)]
        [Size(2)]
        [RuleRequiredField("Country_Iso2Code", DefaultContexts.Save)]
        public string Iso2Code
        {
            get
            {
                return _iso2code;
            }
            set
            {
                SetPropertyValue("Iso2Code", ref _iso2code, value);
            }
        }

        [Indexed(Unique = true)]
        [Size(3)]
        [RuleRequiredField("Country_Iso3Code", DefaultContexts.Save)]
        public string Iso3Code
        {
            get
            {
                return _iso3code;
            }
            set
            {
                SetPropertyValue("Iso3Code", ref _iso3code, value);
            }
        }

        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                SetPropertyValue("IsActive", ref _isActive, value);
            }
        }


        public bool IsDefault
        {
            get
            {
                return _isDefault;
            }
            set
            {
                SetPropertyValue("IsDefault", ref _isDefault, value);
            }
        }



        [Association("Country-CountryStates"),
        Aggregated]
        public XPCollection<CountryState > CountryStates
        {
            get
            {
                return GetCollection<CountryState >("CountryStates");
            }
        }

        [Association("Country-Cities"),
        Aggregated]
        public XPCollection<City> Cities
        {
            get
            {
                return GetCollection<City>("Cities");
            }
        }

        [Association("Country-Currency")]
        public XPCollection<Currency> Currencies
        {
            get
            {
                return GetCollection<Currency>("Currencies");
            }
        }

        [Association("Country-PostOffices")]
        public XPCollection<PostOffice> PostOffices
        {
            get
            {
                return GetCollection<PostOffice>("PostOffices");
            }
        }

        [Association("Country-Language")]
        public XPCollection<Language> Language
        {
            get
            {
                return GetCollection<Language>("Language");
            }
        }
    }
}
